package com.chery.media.ui.dialog

import android.os.Bundle
import android.view.Gravity
import android.view.View
import com.chery.media.R
import com.chery.media.databinding.DialogPasswordBinding
import com.chery.media.library.base.BaseDialogFragment
import com.chery.media.library.base.NoViewModel
import com.chery.media.library.extend.toast

/**
 * 密码弹窗
 */
class PasswordDialog(val listener:(String) -> Unit): BaseDialogFragment<NoViewModel, DialogPasswordBinding>() {
    override val layoutResId: Int
        get() = R.layout.dialog_password

    override fun initView(view: View?, args: Bundle?) {
        mBinding.tvCancel.setOnClickListener {
            dismiss()
        }
        mBinding.tvConfirm.setOnClickListener {
            if (mBinding.etPassword.text.isNullOrEmpty()) {
                "密码不能为空".toast()
                return@setOnClickListener
            }
            listener.invoke(mBinding.etPassword.text.toString())
            dismiss()
        }
    }

    override fun onStart() {
        super.onStart()
        configWindowPercent(Gravity.TOP, 0.5f, 0f)
    }

}